<?php
/**
 * 这个是房源评论的列表获取
 */
 global $_GPC, $_W;
        $uniacid = $this->_uniacid;
        $newhouse_id = $_GPC['infoid'];
        $keyword = $_GPC['keyword'];
        $openid = $_W['openid'];
        $tid = 39; /*这个是获取数据类型*/
        if ($_GPC['tags']) {
            $tid = $_GPC['tags'];
        }
        /*获取某个房源和经纪人的访问人列表*/
        if(isset($_GPC['enews']) &&  $_GPC['enews']=='visiter'){
                $houseid =  intval($_GPC['sid']);
                $keyword = "";
                if($_GPC['keyword']){
                     $keyword = $_GPC['keyword'];
                }
                $limit  = 10;
                $ftype = 11; /*默认新房访客*/
                if(isset($_GPC['limit']) && !empty($_GPC['limit'])){
                    $limit = intval($_GPC['limit']);
                }
                if(isset($_GPC['ftype']) && !empty($_GPC['ftype'])){
                    $ftype = intval($_GPC['ftype']);
                }
                 $sql_add = " uniacid='$uniacid' and ftype='$ftype' and jsondata<>'' and openid<>''  ";
                if($houseid>0){
                     $sql_add.=" and houseid='$houseid' ";
                }      
                if($keyword){
                    $sql_add.=" and ( title like '%$keyword%' )";
                }
                $page = max(1, $_GPC['page']);
                $pagesize = $limit;
                $startlimit = ($page-1)* $pagesize;       
                $ret= pdo_fetchall("select jsondata,last_time from ".tablename("kbwdl_favorite").
                        "  where $sql_add order by  last_time desc limit $startlimit,$pagesize ");
                if(!empty($ret)){
                    foreach($ret as $key=>$val){
                          if($ret[$key]['jsondata']){
                                $jsondata = json_decode($ret[$key]['jsondata'], true);
                              if($jsondata){    
                                   $ret[$key]['nickname'] =  $jsondata['nickname'] ;
                                   $ret[$key]['avatar'] = tomedia($jsondata['avatar'] )  ;
                              }
                           }
                           if(empty($ret[$key]['avatar'])){
                               $ret[$key]['nickname'] =  '访客' ;
                               $ret[$key]['avatar'] = tomedia( "./addons/kbwdl_shequzufang/style/images/house_face.jpg" )  ;
                           }

                         unset($ret[$key]['jsondata']);
                        $ret[$key]['showtime'] = date('Y-m-d',  ($val['last_time']));
                         
                    }
                }
                $data['result'] = $ret;
                /*分类统计*/

                $data['total'] = pdo_fetchcolumn("select count(*) from ".tablename("kbwdl_favorite").
                          " where  $sql_add  ");
                /*是否最后一页*/         
                if($data['total']< $page*$limit){
                    $data['islastpage'] = 1;
                }else{
                    $data['islastpage'] = 0;
                }      
                $this->result(0, 'success', $data);   
                exit;
        }
 
        /*下面是默认获取某个房源的 点赞评分列表*/

        $limit = 4;
        if (isset($_GPC['limit']) && !empty($_GPC['limit'])) {
            $limit = intval($_GPC['limit']);
        }
        $sql_add = " uniacid='$uniacid' and ftype='$tid'  and houseid='$newhouse_id'";
 
     
        $page = max(1, $_GPC['page']);
        $pagesize = $limit;
        $startlimit = ($page - 1) * $pagesize;
        $category = array();
        if(isset($_GPC['total']) && ! empty($_GPC['total'])){
            $total = $_GPC['total'];   
       
        }else{
             $total = pdo_fetchcolumn("select count(*)  from ". tablename("kbwdl_favorite") ."   where $sql_add ");

        }
       
        $ret = pdo_fetchall("select uid,id,addtime,smalltext,ftype,jsondata  from " . tablename("kbwdl_favorite") . "  where $sql_add order by id desc limit $startlimit,$pagesize ");
        if (!empty($ret)) {
            foreach ($ret as $key => $val) {
                $smalltext = explode("|", $val['smalltext']);
                $ret[$key]['content'] = str_replace("留言：",'', $smalltext[0]) ;
                 $ret[$key]['score'] = $smalltext[1];
                $ret[$key]['showtime'] = date('Y年m月d日', $val['addtime'] );
                if($ret[$key]['jsondata']){
                     $jsondata = json_decode($ret[$key]['jsondata'], true);
                   if($jsondata){    
                        $ret[$key]['nickname'] =  $jsondata['nickname'] ;
                        $ret[$key]['avater'] = tomedia($jsondata['avatar'] )  ;
                   }
                }
                if(empty($ret[$key]['avater'])){
                    $ret[$key]['nickname'] =  '访客' ;
                    $ret[$key]['avater'] = tomedia( "./addons/kbwdl_shequzufang/style/images/house_face.jpg" )  ;
                }
              
              unset($ret[$key]['jsondata']);
               
            }
           
        }
        $data['salelist'] = $ret;
 
        $data['total'] = $total;
        $data['commentsql'] ="select uid,id,addtime,smalltext,ftype  from " . tablename("kbwdl_favorite") . "  where $sql_add order by id desc limit $startlimit,$pagesize ";
        $this->result(0, 'success', $data);
?>
